/*
 * generate by table-builder.Don't modify it
 */
using IQIGame.Onigao.Framework.Serialization;
using IQIGame.Onigao.GamePlay;
using System.Collections.Generic;


namespace CfgTable
{
    public partial class TbCfgGuide
    {
        private readonly Dictionary<int, CfgGuide> _dataMap;
        private readonly List<CfgGuide> _dataList;


        public TbCfgGuide(ByteBuf _buf)
        {
            //first read common data
            _TbCommonGuide _commonData = null;
            var commonSize = _buf.ReadSize();
            if (commonSize > 0)
            {
                _commonData = new _TbCommonGuide(_buf);
            }

            //then read row data
            var size = _buf.ReadSize();
            _dataMap = new Dictionary<int, CfgGuide>(size * 3 / 2);
            _dataList = new List<CfgGuide>(size);

            for (int i = 0; i < size; i++)
            {
                CfgGuide _v;
                _v = CfgGuide.DeserializeCfgGuide(_buf, _commonData);
                _dataList.Add(_v);
                _dataMap.Add(_v.Id, _v);
            }

            // read extra fields 

            PostInit();
        }

        public IReadOnlyDictionary<int, CfgGuide> DataMap => _dataMap;
        public IReadOnlyList<CfgGuide> DataList => _dataList;

        public CfgGuide Get(int key)
        {
            if (_dataMap.TryGetValue(key, out var v))
            {
                return v;
            }
            IQIGame.Onigao.Framework.LogGame.LogError("[TbCfgGuide] config not found,id:" + key.ToString());

            return null;
        }

        public CfgGuide GetWithoutError(int key) => _dataMap.TryGetValue(key, out var v) ? v : null;

        /// <summary>
        /// table data file
        /// </summary>
        public static string TableFileName { get; } = "guide";

        /// <summary>
        /// load table function
        /// </summary>
        public static TbCfgGuide LoadFromFunc(System.Func<string, ByteBuf> loadFunc)
        {
            return new TbCfgGuide(loadFunc(TableFileName));
        }

        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();

    }

    public partial class CfgGuide
    {
        private CfgGuide(ByteBuf _buf, _TbCommonGuide _commonData)
        {
            Id = _buf.ReadInt();
            Order = _buf.ReadInt();
            { int dataIndex = _buf.ReadInt() - 1; Content = _commonData._field0[dataIndex]; }
            Enable = _buf.ReadBool();
            Record = _buf.ReadBool();
            Unlimited = _buf.ReadBool();
            { int dataIndex = _buf.ReadInt() - 1; SubIDList = _commonData._field1[dataIndex]; }
            TriggerType = _buf.ReadInt();
            { int dataIndex = _buf.ReadInt() - 1; TriggerValues = _commonData._field2[dataIndex]; }
            KeyID = _buf.ReadInt();
            { int dataIndex = _buf.ReadInt() - 1; Conditions = _commonData._field3[dataIndex]; }
            NextGuide = _buf.ReadInt();
            { int dataIndex = _buf.ReadInt() - 1; Items = _commonData._field4[dataIndex]; }
            ReturnScene = _buf.ReadInt();
            { int dataIndex = _buf.ReadInt() - 1; ReturnUI = _commonData._field5[dataIndex]; }
            IsSkip = _buf.ReadBool();
            GuideGroupId = _buf.ReadInt();
            HideL2D = _buf.ReadBool();

            PostInit();
        }

        internal static CfgGuide DeserializeCfgGuide(ByteBuf _buf, _TbCommonGuide _commonData)
        {
            return new CfgGuide(_buf, _commonData);
        }

        /// <summary>
        /// major key
        /// </summary>
        public int Id { get; private set; }

        /// <summary>
        /// 顺序
        /// </summary>
        public int Order { get; private set; }
        /// <summary>
        /// 中文名称
        /// </summary>
        public string Content { get; private set; }
        /// <summary>
        /// 是否启用
        /// </summary>
        public bool Enable { get; private set; }
        /// <summary>
        /// 是否记录
        /// </summary>
        public bool Record { get; private set; }
        /// <summary>
        /// 可无限触发
        /// </summary>
        public bool Unlimited { get; private set; }
        /// <summary>
        /// 子步骤ID
        /// </summary>
        public IReadOnlyList<int> SubIDList { get; private set; }
        /// <summary>
        /// 触发点类型1开启界面触发2当前步骤完成触发3自定义触发4场景触发
        /// </summary>
        public int TriggerType { get; private set; }
        /// <summary>
        /// 触发参数
        /// </summary>
        public string TriggerValues { get; private set; }
        /// <summary>
        /// 完成关键ID，填-1代表触发就完成
        /// </summary>
        public int KeyID { get; private set; }
        /// <summary>
        /// 触发条件（不能为空）
        /// </summary>
        public string Conditions { get; private set; }
        /// <summary>
        /// 开启后续引导
        /// </summary>
        public int NextGuide { get; private set; }
        /// <summary>
        /// 奖励物品（触发引导之前给）
        /// </summary>
        public IReadOnlyList<int> Items { get; private set; }
        /// <summary>
        /// 还原场景ID
        /// </summary>
        public int ReturnScene { get; private set; }
        /// <summary>
        /// 还原UI
        /// </summary>
        public string ReturnUI { get; private set; }
        /// <summary>
        /// 是否可跳过
        /// </summary>
        public bool IsSkip { get; private set; }
        /// <summary>
        /// 指引组ID（跳过时会一起跳过同一组指引）
        /// </summary>
        public int GuideGroupId { get; private set; }
        /// <summary>
        /// 是否隐藏L2D（1是，0否）
        /// </summary>
        public bool HideL2D { get; private set; }


        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();
    }

    /// <summary>
    /// internal common data.Optimize memory
    /// </summary>
    internal class _TbCommonGuide
    {

        internal IReadOnlyList<string> _field0 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<int>> _field1 { get; private set; }
        internal IReadOnlyList<string> _field2 { get; private set; }
        internal IReadOnlyList<string> _field3 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<int>> _field4 { get; private set; }
        internal IReadOnlyList<string> _field5 { get; private set; }
        internal _TbCommonGuide(ByteBuf _buf)
        {
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field0 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field1 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field2 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field3 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field4 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field5 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
        }

    }
}
